<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateBroadcastExecutionLogTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('broadcast_execution_log', function (Blueprint $table) {
            $table->comment('广播执行日志表');
            $table->bigIncrements('id')->comment('主键ID');
            $table->unsignedBigInteger('plan_id')->nullable()->comment('计划ID');
            $table->tinyInteger('execution_type')->default(1)->comment('执行类型：1-计划执行，2-手动执行，3-应急执行');
            $table->text('broadcast_content')->nullable()->comment('广播内容');
            $table->timestamp('start_time')->nullable()->comment('开始播放时间');
            $table->timestamp('end_time')->nullable()->comment('结束播放时间');
            $table->integer('actual_duration')->nullable()->comment('实际执行时长（秒）');
            $table->tinyInteger('execution_status')->default(1)->comment('执行状态：1-执行中，2-已完成，3-失败');
            $table->string('fail_reason', 1024)->nullable()->comment('失败原因');
            $table->tinyInteger('volume_level')->default(70)->comment('播放音量');
            $table->text('remark')->nullable()->comment('备注');
            $table->unsignedBigInteger('device_id')->comment('设备ID');
            $table->string('file', 255)->comment('文件路径');
            // 索引
            $table->index('plan_id', 'idx_plan_id');
            $table->index('execution_type', 'idx_execution_type');
            $table->index('execution_status', 'idx_execution_status');
            $table->index('start_time', 'idx_start_time');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('broadcast_execution_log');
    }
}